package com.briup.recognition.service.impl;

import com.briup.recognition.bean.Article;
import com.briup.recognition.bean.ArticleExample;
import com.briup.recognition.dao.ArticleMapper;
import com.briup.recognition.service.IArticleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;

@Service
public class ArticleServiceImpl implements IArticleService {

    @Resource
    private ArticleMapper articleMapper;


    @Override
    public List<Article> query() {
        ArticleExample example = new ArticleExample();

        return articleMapper.selectByExample(example);
    }

    @Override
    public Article queryId(Long id) {

        return articleMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Article article) {
        if (article.getId()!=null){
            if(article.getPublishTime()!=null){
                article.setPublishTime(new Date().getTime());
            }
            articleMapper.updateByPrimaryKey(article);
        }else {
            article.setPublishTime(new Date().getTime());
            article.setStatus("未审核");
            articleMapper.insert(article);
        }
    }

    @Override
    public void deleteById(long id) {
        articleMapper.deleteByPrimaryKey(id);
    }
}
